<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>浅拷贝深拷贝</title>
</head>
<script>
    var yyf = {
        name:"yyf",
        team:['ig','lgd',["csi"]]
    }
    var zhou = yyf
    function shallowcopy(obj){
     var copy={}
     for(var  i in obj){
        if(obj.hasOwnProperty(i)){
            copy[i]=obj[i]
        }
     }
     return copy
    }
    // zhou = shallowcopy(yyf)
    zhou = deepcopy(yyf)
    zhou.name="zhou"
    zhou.team.push(["tongfu"])
    zhou.team[2][0]=1
    console.log(yyf)
    console.log(zhou)

    function deepcopy(obj){
        var copy = {}
        var copy  = new obj.constructor()
        if(obj===null){return obj}
        if(obj instanceof Date){return new Date(obj)}
        if(obj instanceof RegExp){return new RegExp(obj)}
        if(typeof obj !=='object'){return obj}
        for(var  i in obj){
        if(obj.hasOwnProperty(i)){
            copy[i]=deepcopy(obj[i])
        }
     }
     return copy

    }
</script>
<body>
    
</body>
</html>